home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Snippets
/
BackInUse 1.0.3
/
BackInUse.c
< prev
next >
Wrap
Text File
|
1996-07-07
|
5KB
|
184 lines
/* ----------------------------------------------------------------------
BackInUse
version 1.0.3
This snippet draws a six point poly, then insets the points a certain
amount and keeps redrawing until it gets to nothing. Then, it erases
the picture and starts the entire process again. Though I don't
believe this program has any commercial value, I have reserved
commercial rights anyway. So, if you want to give it away, please
keep my name in the darn thing; I need to feel appreciated.
Written by: William Woody
Ported to CW by: Ken Long
Updated for CW9 by: Paul Celestin
930724 - 1.0.0 - original version
950711 - 1.0.1 - ported to CW
951201 - 1.0.2 - updated for CW7
960707 - 1.0.3 - updated for CW9
---------------------------------------------------------------------- */
#include <stdio.h>
#include <quickdraw.h> //• What they don't tell you is that you need to
//• include this for the SRAND macro to work...
//extern int Random ();
extern char *malloc ();
#define MAXX 480
#define MAXY 300
#define MAXM 400
WindowPtr theWindow;
WindowRecord wRecord;
Rect dragRect, linesRect;
Rect windowBounds = { 40, 2, 380, 508 };
struct foo {
double a,b; //• This is a point which gets to fly around
struct foo *next;
};
main ()
{
short number,n,x,done = 0;
struct foo *top,*Ptr,*Ptr2;
// struct {
// short top, left, bottom, right;
// } linesRect;
long ticks; //• For the delay in the "splash" screen.
double mx,my,nx,ny;
MaxApplZone();
InitGraf(&qd.thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
//• We can't drag because mouseDown quits us.
//• But it's here if we want to rig it in later.
dragRect = qd.screenBits.bounds;
theWindow = NewWindow (&wRecord, &windowBounds, "\pBackInUse", true, 0,
(WindowPtr)-1L, false, 0L);
SetPort (theWindow);
//• We add a Rect to the window that we can draw in and erase.
SetRect (&linesRect,0,0,500,350);
EraseRect (&linesRect); // let's start with a clean slate
MoveTo (10,25);
TextFont (systemFont); //• System Font is zero, folks.
TextSize (12);
DrawString ("\pBackInUse");
MoveTo (10,40);
DrawString ("\pCopyright©1985-1996 by William Woody, commercial rights reserved.");
MoveTo (10,55);
DrawString ("\pTo halt the program, press the mouse Button.");
TextFont (courier); //• Change font to Courier 12 bold.
TextSize (12);
TextFace (bold);
MoveTo (10,70);
DrawString ("\pPorted to CodeWarrior");
MoveTo (10,85);
DrawString ("\pBy Kenneth A. Long");
GetDateTime ((unsigned long*) &qd.randSeed); //• Seed the random number generator
TextFont (0);
TextSize (12); //• Set all the font stuff back so our SysParams are OK.
TextFace (0);
Delay (240L, &ticks);
EraseRect (&linesRect); //• Get ready for action, after bragging.
while (!done)
{
EraseRect (&linesRect); //• Added to not stack drawings up.
number = (Random () & 3) + 2; //• Number of points generated.
x = 0;
top = Ptr = (struct foo *) malloc(sizeof(struct foo));
//• While horizontal incrementing value is not the same
//• as number of points...
while (x++ != number)
//• ...this stuff is what it is (?).
Ptr = (Ptr->next = (struct foo *) malloc (sizeof(struct foo)));
Ptr = (Ptr->next = top);
mx = 0;
my = 0;
nx = 9999999.0; //• Large numbers for finding minimum value.
ny = 9999999.0;
do
{
Ptr->a = (double) Random ();
if (Ptr->a > mx) mx = Ptr->a;
if (Ptr->a < nx) nx = Ptr->a;
Ptr->b = (double) Random ();
if (Ptr->b > my) my = Ptr->b;
if (Ptr->b < ny) ny = Ptr->b;
Ptr = Ptr->next;
}
//• As long as Ptr ain't the same as top...
while (Ptr != top);
do //• ...make up the points and create "a".
{ //• A circularly linked list of points.
Ptr->a = (Ptr->a - nx) * MAXX / (mx - nx);
Ptr->b = (Ptr->b - ny) * MAXY / (my - ny);
Ptr = Ptr->next; //• Ptr points to next point.
}
//• Again, as long as Ptr ain't the same as top...
while (Ptr != top);
n = 0; //• ..."n" has 0 value.
MoveTo ( (int) Ptr->a, (int) Ptr->b);
//• While that's true, and while incrementing "n" is not the
//• same as 400 times the number of points generated...
while (n++ != MAXM * number)
{ //• ...move the points around, like this:
//• Give "Ptr->a" a value of ITSELF times 40, PLUS
//• the value of "Ptr->next->a" (see above "do loop"),
//• then divide that product by 41. That's the H coord.
Ptr->a = (Ptr->a * 40 + Ptr->next->a) / 41;
//• Same for be to get the V coord.
Ptr->b = (Ptr->b * 40 + Ptr->next->b) / 41;
//• Then draw the line.
LineTo ( (int)Ptr->a, (int)Ptr->b);
Ptr = Ptr->next;
if (Button ()) //• Halt program when Button is pressed.
{
done = 1; //• It's one DONE puppy!
break; //• Unconditionally get the hell out.
}
} //• done with "while".
Ptr = top; //• Clean up the circular linked list.
do
{
Ptr = (Ptr2 = Ptr)->next;
free (Ptr2);
}
while (Ptr != top); //• As long as Ptr aint the top.
EraseRect (&linesRect);
}
}